package com.rao.quartz.controller;

import com.rao.quartz.service.asynService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: raoguang
 * @Date: 2022/05/27/0:48
 * @Description:
 */
@RestController

public class testController {
    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private asynService asynService;

    @GetMapping("/saveLog")
    public void saveLog() {
        logger.info("===========info=========");
        logger.info("===========warn=========");
        logger.info("===========error=========");
    }

    @GetMapping("/testAsyns")
    public String testAsyns() {
        asynService.testAsyns();
        logger.info("============>" + Thread.currentThread().getName());
        return "异步,正在解析......";
    }

    @RequestMapping("/async")
    public String async() {
        System.out.println(Thread.currentThread().getName() + "--IndexController--1");
        asynService.sendSms();
        System.out.println(Thread.currentThread().getName() + "--IndexController--4");
        return "success";
    }

    @GetMapping("/testAsynsTime")
    public void testAsynsTime() throws InterruptedException {

        long begin = System.currentTimeMillis();
        asynService.task1();
        ;
        asynService.task2();
        asynService.task3();
        long end = System.currentTimeMillis();
        System.out.println("主线程：" + Thread.currentThread().getName() + "执行的总耗时：" + (end - begin));
    }


}
